#include <cstdio>
#include <algorithm>
#include <cstring>
#define min(a,b) (((a)<(b))?(a):(b))

using namespace std;

struct Node
{
    int id, a, b, c;
};

bool cmp1( const Node &a, const Node &b )
{
    return a.a > b.a;
}

bool cmp2( const Node &a, const Node &b )
{
    return a.b > b.b;
}

bool cmp3( const Node &a, const Node &b )
{
    return a.a * b.c > b.a * a.c;
}

bool cmp4( const Node &a, const Node &b )
{
    return a.b * b.c > b.b * a.c;
}

Node a[ 100001 ], b[ 100001 ];
int f[ 100001 ], s[ 100001 ], p[ 100001 ];

int main( )
{
    int n, m, i, j, q;
    while ( scanf("%d%d", &n, &m) != EOF )
    {
        memset( f, 0x3f, sizeof( f ) );
        for ( i = 0; i < n; i++ )
        {
            scanf("%d%d%d", &a[ i ].a, &a[ i ].b, &a[ i ].c);
            a[ i ].id = i;
        }
        j = 0;
        for ( i = 0; i < m; i++ )
        {
            scanf("%d", &p[ i ]);
            b[ j++ ] = a[ p[ i ] ];
        }
        sort( b, b + m, cmp1 );
        q = 1;
        for ( i = 0; i < m; i++ )
        {
            if ( f[ b[ i ].id ] > q )
            {
                f[ b[ i ].id ] = q;
                s[ b[ i ].id ] = 1;
            }
            if ( i != m - 1 && cmp1( b[ i ], b[ i + 1 ] ) )
                q = i + 2;
        }
        sort( b, b + m, cmp2 );
        q = 1;
        for ( i = 0; i < m; i++ )
        {
            if ( f[ b[ i ].id ] > q )
            {
                f[ b[ i ].id ] = q;
                s[ b[ i ].id ] = 2;
            }
            if ( i != m - 1 && cmp2( b[ i ], b[ i + 1 ] ) )
                q = i + 2;
        }
        sort( b, b + m, cmp3 );
        q = 1;
        for ( i = 0; i < m; i++ )
        {
            if ( f[ b[ i ].id ] > q )
            {
                f[ b[ i ].id ] = q;
                s[ b[ i ].id ] = 3;
            }
            if ( i != m - 1 && cmp3( b[ i ], b[ i + 1 ] ) )
                q = i + 2;
        }
        sort( b, b + m, cmp4 );
        q = 1;
        for ( i = 0; i < m; i++ )
        {
            if ( f[ b[ i ].id ] > q )
            {
                f[ b[ i ].id ] = q;
                s[ b[ i ].id ] = 4;
            }
            if ( i != m - 1 && cmp4( b[ i ], b[ i + 1 ] ) )
                q = i + 2;
        }
        for ( i = 0; i < m; i++ )
            printf("%d:%d\n", f[ p[ i ] ], s[ p[ i ] ]);
        puts("");
    }
    return 0;
}
